package com.chen.pfm.provider;


import com.chen.pfm.ResourceTable;
import com.chen.pfm.entity.Account;
import com.chen.pfm.entity.Classify;
import com.chen.pfm.utils.ClassifyDBUtil;
import com.chen.pfm.utils.MyUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.DataAbilityRemoteException;
import ohos.agp.components.*;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.List;

public class AccountProvider extends BaseItemProvider {
    static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x2022001, "AccountProvider");

    private AbilitySlice slice;
    private List<Account> list;
    public AccountProvider(List<Account> list, AbilitySlice slice) {
        this.list = list;
        this.slice = slice;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        if (list != null && i >= 0 && i < list.size()) {
            return list.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        final DirectionalLayout cpt;

        if (component == null) {
            cpt = (DirectionalLayout) LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_template_items_account, null, false);

        } else {
            cpt = (DirectionalLayout) component;
        }
        Account account = list.get(i);
        //设置属性返回
        Text aremark = (Text) cpt.findComponentById(ResourceTable.Id_item_aremark);
        aremark.setText(account.getAremark());
        Text amoney = (Text) cpt.findComponentById(ResourceTable.Id_item_amoney);
        amoney.setText(MyUtil.getStrBalance(account.getAmoney()));
        return cpt;
    }
}
